<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>

<script>
    let p = new Promise((resolve,reject) => {
        $.ajax({
            url:"",
            success:function (data) {
                console.log()
                //成功就调用p.then
                resolve(data)
            },
            error:function (err) {
                reject(err)
            }
        });
    })

    p.then((obj) => {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "",
                success:function (data) {
                    console.log()
                    //成功就调用p.then
                    resolve(data)
                },
                error:function (err) {
                    reject(err)
                }
            });
        })
    })
    .then((data) => {
        $.ajax({
            // ...
            //如果成功还可以调用后面的p.then,但前提是要返回异步promise
        })
    })

    //代码抽取
    function get(url, data) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url:url,
                data:data,
                success:function (data) {
                    resolve(data)
                },
                error:function (err) {
                    reject(err)
                }
            })
        })
    }
    get('url')
    .then((data) => {
        console.log("查询用户成功")
        return get('urL',data)
    })
    .then((data) => {
        console.log("查询课程成功")
        return get('url',data)
    })
    .then((data) => {
        console.log("查询成绩成功",data)
    })
</script>

</body>
</html>